<?php
include_once('../../app/connection.php');

if(isset($_POST['action']))
{
    $action = $_POST['action'];
    if($action == "get_info" && $_POST['magv'] != "")
    {
        $magv=""; $array="";
        $magv = $_POST['magv'];
            
        $sql = "SELECT * FROM giaovien WHERE MAGIAOVIEN LIKE'".$magv."%'";
        $result = mysql_query($sql);
        
        if(mysql_num_rows($result)!=0)
        {            
            $string = "";
            while($row = mysql_fetch_assoc($result))
            {
                $string .=  $row['MAGIAOVIEN'].',';               
            }
            $count = count($array);
            echo $string;
        }
    }
    
    if($action == "Chỉnh sửa")
    {
        $magv="";
        $magv = $_POST['magv'];
        $sql = "UPDATE giaovien SET HOTEN='".$_POST['hoten']."', GIOITINH='".$_POST['gioitinh']."', 
            NGAYSINH='".$_POST['namsinh']."', MAKHOA='".$_POST['khoa']."' WHERE MAGIAOVIEN='$magv'";
        $sql = "UPDATE giaovien SET HOTEN='".$_POST['hoten']."', GIOITINH='".$_POST['gioitinh']."', 
            NGAYSINH='".$_POST['ngaysinh']."', MAKHOA='".$_POST['khoa']."' WHERE MAGIAOVIEN='$magv'";
        $result = mysql_query($sql) or die("Co loi xay ra");
        
        header('Location: ../?page=quanlygv&function=ds_gv');
    }  
}
?>